home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 4.iso
/
src
/
haeberli
/
fonttools
/
adjustfont.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-01
|
4KB
|
193 lines
/*
* Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
* All Rights Reserved.
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
* the contents of this file may not be disclosed to third parties, copied or
* duplicated in any form, in whole or in part, without the prior written
* permission of Silicon Graphics, Inc.
*
* RESTRICTED RIGHTS LEGEND:
* Use, duplication or disclosure by the Government is subject to restrictions
* as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
* and Computer Software clause at DFARS 252.227-7013, and/or in similar or
* successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
* rights reserved under the Copyright Laws of the United States.
*/
/*
* adjustfont -
* Adjust an object font.
*
* Paul Haeberli - 1990
*
*/
#include "gl.h"
#include "device.h"
#include "stdio.h"
#include "objfnt.h"
float fgetmousex();
float fgetmousey();
int curchar;
objfnt *fnt;
main(argc,argv)
int argc;
char **argv;
{
short val;
float pos;
float ixpos, iypos;
float xpos, ypos;
int dx, dy;
int xmove, ymove;
curchar = 'A';
if( argc<3 ) {
fprintf(stderr,"usage: adjustfont file.of out.of\n");
exit(1);
}
fnt = readobjfnt(argv[1]);
if(!fnt) {
fprintf(stderr,"adjustfont: can't open input file\n");
exit(1);
}
keepaspect(4,3);
winopen("adjustfont");
subpixel(1);
RGBmode();
doublebuffer();
gconfig();
makeframe();
qdevice(LEFTMOUSE);
qdevice(MIDDLEMOUSE);
qdevice(UPARROWKEY);
qdevice(DOWNARROWKEY);
while(1) {
switch(qread(&val)) {
case REDRAW:
makeframe();
break;
case LEFTMOUSE:
if(val) {
if(!getcharadvance(fnt,curchar,&xmove,&ymove))
break;
ixpos = getmousex();
iypos = getmousey();
while(getbutton(LEFTMOUSE)) {
xpos = getmousex();
ypos = getmousey();
dx = xpos-ixpos;
dy = ypos-iypos;
if(shiftdown()) {
xmove = xmove+dx;
addcharmetrics(fnt,curchar,xmove,ymove);
} else {
translatechar(fnt,curchar,dx,dy);
}
showchar(fnt,curchar);
ixpos = xpos;
iypos = ypos;
}
} else {
writeobjfnt(argv[2],fnt);
}
break;
case MIDDLEMOUSE:
if(val) {
while(getbutton(MIDDLEMOUSE)) {
pos = fgetmousex();
curchar = 32+(int)(96*pos);
showchar(fnt,curchar);
}
}
break;
case UPARROWKEY:
if(val) {
curchar++;
if(curchar>(32+96))
curchar = 32+96;
showchar(fnt,curchar);
}
break;
case DOWNARROWKEY:
if(val) {
curchar--;
if(curchar<(32))
curchar = 32;
showchar(fnt,curchar);
}
break;
}
}
}
makeframe()
{
reshapeviewport();
ortho2(-0.1,1.9,-0.5,1.0);
cpack(0x00ffffff);
clear();
swapbuffers();
showchar(fnt,curchar);
}
showchar(fnt,c)
objfnt *fnt;
int c;
{
int didit;
float swidth;
int xmove, ymove;
cpack(0x00ffffff);
clear();
pushmatrix();
translate(0.2,0.0,0.0);
cpack(0x00808080);
move2(-100.0,0.0);
draw2(100.0,0.0);
move2(-100.0,0.4);
draw2(100.0,0.4);
move2(-100.0,0.6);
draw2(100.0,0.6);
pushmatrix();
scale(1.0/fnt->scale,1.0/fnt->scale,0.0);
cpack(0x000000ff);
rectf(0.0,0.0,10.0,10.0);
cpack(0x00000000);
if(drawobjchar(fnt,c)) {
getcharadvance(fnt,c,&xmove,&ymove);
cpack(0x000000ff);
rectf(0.0,0.0,10.0,10.0);
cpack(0x000000ff);
/* bboxshow(str); */
cpack(0x00000000);
drawobjchar(fnt,c);
popmatrix();
} else
popmatrix();
popmatrix();
swapbuffers();
}
int xtrans, ytrans;
static warpfunc(s)
short s[2];
{
s[0] = s[0] + xtrans;
s[1] = s[1] + ytrans;
}
translatechar(fnt,c,dx,dy)
objfnt *fnt;
int c, dx, dy;
{
xtrans = dx;
ytrans = dy;
applytocharverts(fnt,c,warpfunc);
}